/*
                  StringUtil Implementation
*/
#include "StringUtil.h"

vector<string> SplitString(const string& strString, const string& strSplitBy = " ")
{
    int iLastString = 0;
    int i = strString.find(strSplitBy);
    vector<string> Return;

    while (i != string::npos)
    {
        Return.push_back(strString.substr(iLastString, i - iLastString));

        iLastString = i + strSplitBy.length();
        i = strString.find(strSplitBy, i + 1);
    }

    Return.push_back(strString.substr(iLastString));

    return Return;
}

string StringReplace(const string& strString, const string& strReplace, const string& strReplaceWith)
{
    string strReturn = "";

    int iLastFound = 0;
    int i = strString.find(strReplace);

    if (i == string::npos)
    {
        return strString;
    }

    while (i != string::npos)
    {
        strReturn += strString.substr(iLastFound, i - iLastFound);
        strReturn += strReplaceWith;

        iLastFound = i + strReplace.length();
        i = strString.find(strReplace, i + 1);
    }

    strReturn += strString.substr(iLastFound);

    return strReturn;
}
